package com.wuliming.gulimall.product.web;

import com.wuliming.gulimall.product.entity.CategoryEntity;
import com.wuliming.gulimall.product.entity.vo.CateLeve2Vo;
import com.wuliming.gulimall.product.service.CategoryService;
import org.bouncycastle.math.raw.Mod;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@Controller
public class IndexController {

    @Autowired
    private CategoryService categoryService;

    @GetMapping({"/","/index.html", "/index"})
    public String index(Model model) {
        List<CategoryEntity> category = categoryService.getLevel1Category();
        model.addAttribute("categorys",category);
        return "index";
    }

    @GetMapping("/index/catalog.json")
    @ResponseBody
    @Cacheable(value = {"category"},key = "'level1Categorys'")
    public Map<String,List<CateLeve2Vo>> getCatalogJson() {
        Map<String,List<CateLeve2Vo>> map = categoryService.getCatalogJson();
        return map;
    }

}
